<?php
namespace app\model;
use app\BaseModel;
use think\model\concern\SoftDelete;
use app\model\Member;

class MemberCoupon extends BaseModel
{

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';
    protected $hidden = ['update_time','delete_time','sort','status'];



    public function searchMemberIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('member_id','=',$value);
        }
    }
    public function searchStatusAttr($query,$value,$data){

            $query->where('status','=',$value);

    }

    public function searchBigPriceAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('big_price','<=',$value);
        }
    }



    protected function setMemberIdAttr($value,$data){ //当前字段的修改器
         $member = Member::where('id',$value)->find();
         $this->set('member_mobile',$member['mobile']);
         $this->set('member_name',$member['name']);
         return $value;
    }
    protected function setStatusAttr($value,$data){ //当前字段的修改器
         $status = [3=>'未激活',0=>'未使用',1=>'已使用',2=>'已过期'];
         $this->set('status_title',$status[$data['status']]);
         return $value;
    }





}